import request from '@/utils/request'
import DetailsCustomForm from '../support/Form'
import CustomForm from './Form/index.vue'
import HandleForm from './Handle/index.vue'
import HandleRecordsForm from './Records/index.vue'
export default {
  name: 'insurance',
  components: { CustomForm, HandleRecordsForm, HandleForm, DetailsCustomForm },
  data() {
    return {
      showAll: false,
      query: {
        campusId: undefined,
        campus: undefined,
        campusStatus: undefined,
        status: undefined,
        brand: '',
        followupStatus: undefined
      },
      list: [],
      listLoading: true,
      multipleSelection: [],
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: 'desc',
        sidx: 'priority desc, followupStatus,createTime'
      },
      formVisible: false,
      detailsFormVisible: false,
      recordsVisible: false,
      handleVisible: false,
      brandOptions: [],
      levelOptions: [],
      followUpMethodOptions: [
        {
          enCode: '1',
          fullName: '协商沟通'
        },
        {
          enCode: '2',
          fullName: '激活续费'
        },
        {
          enCode: '3',
          fullName: '工商维权'
        },
        {
          enCode: '4',
          fullName: '侵权诉讼'
        }
      ],
      handlesOptions: [
        {
          enCode: '1',
          fullName: '跟进中'
        },
        {
          enCode: '2',
          fullName: '已完成'
        }
      ],
      violationlssueOptions: [
        {
          enCode: '1',
          fullName: '合同解除，未拆品牌标识'
        },
        {
          enCode: '2',
          fullName: '品牌竞业，违约经营'
        },
        {
          enCode: '3',
          fullName: '贝尔品牌，其他违约'
        },
        {
          enCode: '4',
          fullName: '其它机构侵权'
        }
      ]
    }
  },
  computed: {},
  created() {
    this.initData()
  },
  mounted() {
    this.$store.dispatch('base/getDictionaryData', { sort: 'Brand' }).then(res => {
      res.push({ enCode: 'other', fullName: '非贝尔安亲体系' })
      this.brandOptions = res
    })
    this.$store.dispatch('base/getDictionaryData', { sort: 'CampusLevel' }).then(res => {
      this.levelOptions = res
    })
  },
  methods: {
    initData() {
      this.listLoading = true
      let _query = {
        ...this.listQuery,
        ...this.query
      }
      let query = {}
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join()
        } else {
          query[key] = _query[key]
        }
      }
      request({
        url: `/api/campus/violationscases`,
        method: 'GET',
        data: query
      }).then(res => {
        this.list = res.data.list
        this.total = res.data.pagination.total
        this.listLoading = false
      })
    },
    handleDel(id) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        type: 'warning'
      })
        .then(() => {
          request({
            url: `/api/system/CampusInsuranceRecords/${id}`,
            method: 'DELETE'
          }).then(res => {
            this.$message({
              type: 'success',
              message: res.msg,
              onClose: () => {
                this.initData()
              }
            })
          })
        })
        .catch(() => {})
    },
    handlePriority(id, type) {
      this.$confirm((type ? '取消' : '标记') + '该数据为重点关注, 是否继续?', '提示', {
        type: 'warning'
      })
        .then(() => {
          request({
            url: `/api/campus/violationscases/${id}/priority`,
            method: 'post'
          }).then(res => {
            this.$message({
              type: 'success',
              message: res.msg,
              onClose: () => {
                this.initData()
              }
            })
          })
        })
        .catch(() => {})
    },
    handleCommandDown(command) {
      window.open(command)
    },
    handGetDetails(id, isDetail) {
      this.detailsFormVisible = true
      this.$nextTick(() => {
        this.$refs.DetailsCustomForm.init(id, isDetail)
      })
    },
    addOrUpdateHandle(row, isDetail) {
      let data = Object.assign({}, row)
      console.log(data)
      // data.brand = data.brand ? data.brand : 'noBell'
      this.formVisible = true
      this.$nextTick(() => {
        this.$refs.CustomForm.init(data, isDetail)
      })
    },
    addHandle(id) {
      this.handleVisible = true
      this.$nextTick(() => {
        this.$refs.HandleForm.init(id)
      })
    },
    recordsHandle(id) {
      this.recordsVisible = true
      this.$nextTick(() => {
        this.$refs.RecordsForm.init(id)
      })
    },
    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 50,
        sort: 'desc',
        sidx: 'priority desc, followupStatus,createTime'
      }
      this.initData()
    },
    refresh(isrRefresh) {
      // if (this.formVisible) {
      //   this.formVisible = false
      // }
      if (this.recordsVisible) {
        this.recordsVisible = false
      }
      if (this.detailsFormVisible) {
        this.detailsFormVisible = false
      }
      if (isrRefresh) this.reset()
    },
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined
      }
      this.listQuery = {
        currentPage: 1,
        pageSize: 50,
        sort: 'desc',
        sidx: 'priority desc, followupStatus,createTime'
      }
      this.initData()
    }
  }
}
